package com.liam.design.observer.sub;

import com.liam.design.observer.obs.Observer;

import java.util.ArrayList;
import java.util.List;

/**
 * 目标对象 负责把最新数据存入观察者中
 */
public class Subject {

    private List<Observer> observerList = new ArrayList<Observer>();

    public void attach(Observer o){
        observerList.add(o);
    }

    public void detach(Observer o ){
        observerList.remove(o);
    }


    protected void notifyObserver(){
        for (Observer o : observerList){
            o.update(this);
        }
    }

}
